<?php
if(isset($_GET['user_id']) && is_numeric($_GET['user_id']))
	$uid=$_GET['user_id'];
else
	$uid=$this->user_id;
	
$edit=false;
if($uid==$this->user_id)
	$edit=true;

$this->sql->query("SELECT us.user_name, ally_tag FROM ".$this->sql->getpre()."users us LEFT JOIN ".$this->sql->getpre()."ally ON user_ally=ally_id WHERE us.user_id=$uid;");
$this->sql->fetch_assoc();
$this->addTitle($lang['users']['forschung_title']." - ".$this->sql->row["user_name"]);



echo "<h3>".$lang['users']['forschung_title']." <span style=\"font-size:80%\">von ".$this->sql->row["user_name"]." <span style=\"font-size:80%\">(".$this->sql->row["ally_tag"].")"."</span></span></h3>";
echo "\n";

echo "
<a href=\"?com=201&user_id=$uid\"><img src=\"images/icon_fleet.png\" /></a>
<a href=\"?com=200&user_id=$uid\"><img src=\"images/icon_planeten.png\" /></a>
<a href=\"?com=203&user_id=$uid\"><img src=\"images/icon_statts.png\" /></a>
<a href=\"?com=202&user_id=$uid\"><img src=\"images/icon_forschung.png\" /></a><br /><br />";

if($edit && isset($_POST['forschung'])){
	//echo "update";
	//echo "<pre>";
	//print_r($_POST);
	//echo "</pre>";

	$sql="UPDATE 
		".$this->sql->getpre()."forschung
	SET
		forschung_spionagetechnik = '".$_POST['forschung'][$lang['forschung']['spiotech']]."',
		forschung_computertechnik = '".$_POST['forschung'][$lang['forschung']['comptech']]."',
		forschung_waffentechnik = '".$_POST['forschung'][$lang['forschung']['wtech']]."',
		forschung_schildtechnik = '".$_POST['forschung'][$lang['forschung']['schild']]."',
		forschung_raumschiffpanzerung = '".$_POST['forschung'][$lang['forschung']['panzer']]."',
		forschung_energietechnik = '".$_POST['forschung'][$lang['forschung']['energie']]."',
		forschung_hyperraumtechnik = '".$_POST['forschung'][$lang['forschung']['hypertech']]."',
		forschung_verbrennungstriebwerk = '".$_POST['forschung'][$lang['forschung']['vtrieb']]."',
		forschung_impulstriebwerk = '".$_POST['forschung'][$lang['forschung']['itrieb']]."',
		forschung_hyperraumantrieb = '".$_POST['forschung'][$lang['forschung']['htrieb']]."',
		forschung_lasertechnik = '".$_POST['forschung'][$lang['forschung']['laser']]."',
		forschung_ionentechnik = '".$_POST['forschung'][$lang['forschung']['ionen']]."',
		forschung_plasmatechnik = '".$_POST['forschung'][$lang['forschung']['plasma']]."',
		forschung_forschungsnetzwerk = '".$_POST['forschung'][$lang['forschung']['forschnetz']]."',
    forschung_expeditionstechnik = '".$_POST['forschung'][$lang['forschung']['expedition']]."',
		forschung_gravitonforschung = '".$_POST['forschung'][$lang['forschung']['gravi']]."'
	WHERE 
		user_id=".$uid.";";
	
	$this->sql->queryS($sql);
	
	echo "<span style=\"color:green;\">".$lang['admin']['info_saved']."</span>";
}

if($uid == $this->user_id){
	$lines="WHERE us.user_id=".$this->user_id;
}else{
	$sql_reduce="\n\tAND\n\tal.show_planeten=1";
	if(in_array($this->user_group, $restrict_ally_group) or in_array($this->user_id, $restrict_ally_user))
		$sql_reduce="\n\tAND\n\tal.ally_id=".$this->user_ally_id;
	if(in_array($this->user_group, $restrict_user_group) or in_array($this->user_id, $restrict_user_user))
		$sql_reduce="\n\tAND\n\tus.user_id=".$this->user_id;
	
	$lines="WHERE us.user_id=$uid $sql_reduce";
}

$sql="SELECT 
	forschung_spionagetechnik AS '".$lang['forschung']['spiotech']."',
	forschung_computertechnik AS '".$lang['forschung']['comptech']."',
	forschung_waffentechnik AS '".$lang['forschung']['wtech']."',
	forschung_schildtechnik AS '".$lang['forschung']['schild']."',
	forschung_raumschiffpanzerung AS '".$lang['forschung']['panzer']."',
	forschung_energietechnik AS '".$lang['forschung']['energie']."',
	forschung_hyperraumtechnik AS '".$lang['forschung']['hypertech']."',
	forschung_verbrennungstriebwerk AS '".$lang['forschung']['vtrieb']."',
	forschung_impulstriebwerk AS '".$lang['forschung']['itrieb']."',
	forschung_hyperraumantrieb AS '".$lang['forschung']['htrieb']."',
	forschung_lasertechnik AS '".$lang['forschung']['laser']."',
	forschung_ionentechnik AS '".$lang['forschung']['ionen']."',
	forschung_plasmatechnik AS '".$lang['forschung']['plasma']."',
	forschung_forschungsnetzwerk AS '".$lang['forschung']['forschnetz']."',
  forschung_expeditionstechnik AS '".$lang['forschung']['expedition']."',
	forschung_gravitonforschung AS '".$lang['forschung']['gravi']."'
FROM ".$this->sql->getpre()."users us
	LEFT JOIN ".$this->sql->getpre()."planet pl ON pl.user_id=us.user_id
	LEFT JOIN ".$this->sql->getpre()."ally al ON al.ally_id=us.user_ally
	LEFT JOIN ".$this->sql->getpre()."fleet fl ON fl.user_id=us.user_id
	LEFT JOIN ".$this->sql->getpre()."forschung fo ON fo.user_id=us.user_id ".$lines;


$this->sql->query($sql);
$this->sql->fetch_assoc();



echo "<div align=\"center\"><form action=\"\" method=\"post\" name=\"update\"><table width=\"530\">";
$c=1;
foreach($lang['forschung'] as $key=>$value){
	echo "<tr>";
		if($this->user_data['show_bild']==1){
			echo "<td class=\"l\">";
				echo "<img src=\"".$this->user_skin.$lang['forschung_link'][$key]."\" align=\"top\" border=\"0\" height=\"120\" width=\"120\" />";
			echo "</td>";
		}
		
		echo "<td class=\"l\">";
			echo "<strong>".$value."</strong><br />";
			if($this->user_data['show_text']==1)
				echo $lang['forschung_txt'][$key];
		echo "</td>";
		
		echo "<td class=\"k\">";
			if(strlen($this->sql->row[$value])>0){
				if($edit)
					echo "<input ";
				else
					echo "<input readonly=\"true\" ";
				echo "name=\"forschung[$value]\" size=\"6\" maxlength=\"6\" value=\"".$this->sql->row[$value]."\" tabindex=\"$c\">";
			}else
				echo " - ";
		echo "</td>";
	echo "</tr>";
	$c++;
}
if($edit)
	echo "<tr><td class=\"c\" colspan=\"3\" align=\"center\"><input value=\"Absenden\" type=\"submit\"></td></tr>";
echo "</table></div>";
?>
